# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2022/7/26 0026 1:40
# @Author    :jiaxuesong


#封装app调用入口
# 导包
from appium import webdriver
import time
from appium_test.common.log import *
from appium_test.common.readConfig import ReadConfig
from multiprocessing import Pool


# 封装driver类
class Driver(object):
    device_name = None
    port = None
    print(port)
    #定义初始化函数，保存app配置
    def __init__(self):
        # 定义类属性
        # 实例化读取配置文件类
        re = ReadConfig()
        # 获取配置文件中配置的APP属性
        self.desire_caps = {
                "deviceName": self.device_name,
                "platformName":re.get_config('APP', 'platformName'),
                "platformVersion":re.get_config('APP', 'platformVersion'),
                "appPackage":re.get_config('APP', 'appPackage'),
                "appActivity":re.get_config('APP', 'appActivity'),
                "noReset":re.get_config('APP', 'noReset'),
                "unicodeKeyboard":re.get_config('APP', 'unicodeKeyboard'),
                "autoLaunch":re.get_config('APP', 'autoLaunch')
        }

    #封装对外调用方法startUp
    def startUp(self):
        logger.info('启动中.......')
        driver = webdriver.Remote('http://127.0.0.1:' + str(self.port) + '/wd/hub', self.desire_caps)
        logger.info('启动成功......')
        time.sleep(3)
        driver.implicitly_wait(5)
        return driver

# def run(x, y):
#     Driver.device_name = x
#     Driver.port = y
#
#     dri = Driver().startUp()
#     time.sleep(10)
#     dri.quit()
#
#
# if __name__ == '__main__':
#     # re = Driver().startUp()
#     # func = Public(re)
#     # func.swipeRight()
#     serverlist= [('127.0.0.1:21503', '4723'), ('127.0.0.1:21513', '4725')]
#     re = []
#     pool = Pool(len(serverlist))
#     for i, j in serverlist:
#         res = pool.apply_async(run, (i, j))
#         re.append(res)
#
#     for i in re:
#         i.get()
#
#     print('__________________')

